package screen;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;

public class ScreenBuffer {

	public static final Dimension SCREEN = new Dimension(800, 600);

	private Pixel[][] pixelBuffer;

	public ScreenBuffer() {
		pixelBuffer = new Pixel[(int) SCREEN.getWidth()][(int) SCREEN
				.getHeight()];
		for (int i = 0; i < pixelBuffer.length; i++) {
			for (int j = 0; j < pixelBuffer[i].length; j++) {
				pixelBuffer[i][j] = new Pixel();
			}
		}
	}

	public void addColorToPixel(Point2D pixel, Color color) {
		pixelBuffer[(int) pixel.getX()][(int) pixel.getY()].addColor(color);
	}

	public void draw(Graphics2D g2d) {
		for (int i = 0; i < pixelBuffer.length; i++) {
			for (int j = 0; j < pixelBuffer[i].length; j++) {
				g2d.setColor(pixelBuffer[i][j].averageColors());
				g2d.fillRect(i, j, 1, 1);
			}
		}
	}
}
